﻿<Window x:Class="EditSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=TreeViewEx"
        xmlns:Model="clr-namespace:EditSample.Model" Title="MainWindow" Height="350" Width="261"
        xmlns:cp="clr-namespace:TreeViewEx.SimpleSample"
        AutomationProperties.Name="TestApp2Window">
    <Window.Resources>
        <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type Model:Node}">
            <StackPanel Orientation="Horizontal">
                <Border CornerRadius="2" Width="15" Height="15" Background="{Binding Color}" Margin="0,0,5,0"/>
                <TextBlock Text="{Binding Name}" />
            </StackPanel>
        </HierarchicalDataTemplate>
        
        <Style TargetType="Controls:TreeViewExItem">
            <Setter Property="IsEditable" Value="{Binding Editable}" />
            <Setter Property="TemplateEdit">
                <Setter.Value>
                    <DataTemplate>
                        <cp:ColorPicker SelectedColor="{Binding Color, Mode=TwoWay}" Colors="{Binding Colors}" 
                                Editing="{Binding IsEditing, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type Controls:TreeViewExItem}}}"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            
            <Style.Triggers>
                <Trigger Property="IsEditable" Value="False">
                    <Setter Property="Foreground" Value="Gray" />
                </Trigger>
                <Trigger Property="IsEditable" Value="True">
                    <Setter Property="Foreground" Value="Black" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <DockPanel>
        <Controls:TreeViewEx AutomationProperties.Name="TestApp2Tree" ItemsSource="{Binding Path=Children}" />
    </DockPanel>
</Window>
